package com.briup.app02.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.app02.bean.BaseLogExample;
import com.briup.app02.bean.BaseLog;
import com.briup.app02.dao.BaseLogMapper;
import com.briup.app02.service.IBaseLogService;
import com.briup.app02.utils.CustomerException;

	@Service
	public class BaseLogServiceImpl implements IBaseLogService {
		@Autowired
		private BaseLogMapper baselogMapper;
		
		@Override
		public List<BaseLog> query(String realname) {
			// 模板查询
			BaseLogExample example = new BaseLogExample();
			if(realname!=null){
				example.createCriteria().andRealnameLike("%"+realname+"%");
			}
			List<BaseLog> list = baselogMapper.selectByExample(example);
			return list;
		}

		@Override
		public void saveOrUpdate(BaseLog baselog) throws CustomerException{
			if(baselog.getId() != null) {
				baselogMapper.insert(baselog);
			} else {
				baselogMapper.updateByPrimaryKey(baselog);
			}
		}

		@Override
		public void deleteById(long id) throws CustomerException{
			BaseLog baseLog = baselogMapper.selectByPrimaryKey(id);
			if (baseLog == null ) {
				throw new CustomerException("要删除的分类信息不存在");
			}
			baselogMapper.deleteByPrimaryKey(id);
		}

}
